package com.fengyunhe.manager.web;

import com.fengyunhe.common.bean.PageList;
import com.fengyunhe.common.bean.Page.Offset;
import com.fengyunhe.manager.dao.entity.AdminLogEntity;
import com.fengyunhe.manager.service.AdminLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 管理操作日志
 *
 * @author Administrator
 */
@Controller
@RequestMapping("/admin/log")
public class AdminLogController extends AdminBaseController {

    static final String MODULE_ID = "manager.log";
    static final String MODULE_NAME = "操作日志";
    @Autowired
    private AdminLogService adminLogService;

    /**
     * 查看操作日志
     *
     * @param page
     * @param moduleName
     * @return
     */
    @ResponseBody
    @RequestMapping("/list.do")
    @RequiresPermissions(MODULE_ID + ":view")
    public Map<String, Object> list(Offset page, String moduleName) {
        Map<String, Object> map = new HashMap<String, Object>();
        boolean success = false;
        String msg = null;
        try {
            PageList<AdminLogEntity> pageList = adminLogService.findByPage(page, moduleName);
            map.put("pageList", pageList);
            success = true;
        } catch (Exception e) {
            log.error("查询操作日志列表出错", e);
            success = false;
            msg = "查询操作日志列表出错";
            e.printStackTrace();
        }
        map.put("success", success);
        map.put("msg", msg);

        return map;
    }

}
